﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace INF7GEN
{
	

	public partial class Form1 : Form
	{


		#region Fields 
		
		//default selected value, for multi selections is always -1
		private GlobalStates Game;
		private int selectedAction = -1;
		private int selectedPerson = -1;
		private int selectedRoom = -1;
		private int selectedRoomD = -1;
		private int selectedRoomE = -1;
		private int selectedRoomN = -1;
		private int selectedRoomS = -1;
		private int selectedRoomU = -1;
		private int selectedRoomW = -1;
		private int selectedThing = -1;
		private int selectedUserCommand = -1;
		private int selectedADVBookPage = -1;
		private int selectedADVBookChoice = -1;
		private int selectedADVBookFlag = -1;
		private int caretPos = 0;

		#endregion Fields 

		#region Constructors

		public Form1(string s)
		{
			InitializeComponent();
		}

		public Form1()
		{
			InitializeComponent();
		}

		#endregion Constructors 


		#region Methods
		
		private void Form1_Load(object sender, EventArgs e)
		{
			Game = new GlobalStates();

			//thing types
			foreach(string s in GlobalStates.type)
				domainUpDownThingType.Items.Add(s);
			foreach (string s in UserCommand.Logic)
				domainUpDownUserCommandLogic.Items.Add(s);
			foreach (string s in UserCommand.Action)
				domainUpDownUserCommandAction.Items.Add(s);
			foreach (string s in UserCommand.Arguments)
				domainUpDownUserCommandArguments.Items.Add(s);

			foreach (string s in Action.NumberOfObjects)
				domainUpDownActionNumberOfObjects.Items.Add(s);
			foreach (string s in Action.OptionalLit)
				domainUpDownActionOptionalLit.Items.Add(s);
			foreach (string s in Action.Requirenments)
				domainUpDownActionRequirenments.Items.Add(s);
			
		}

		private void Form1_ResizeEnd(object sender, EventArgs e)
		{
			this.Height = 600;
			this.Width = 800;
		}

		#region Project

		private void textBoxAuthorName_TextChanged(object sender, EventArgs e)
		{
			Game.AuthorName = textBoxAuthorName.Text;
			UpdateGame();
		}

		private void textBoxProjectName_TextChanged(object sender, EventArgs e)
		{
			Game.ProjectName = textBoxProjectName.Text;
			UpdateGame();
		}

		private void textBoxStoryHeadline_TextChanged(object sender, EventArgs e)
		{
			Game.StoryHeadline = textBoxStoryHeadline.Text;
			UpdateGame();
		}

		private void buttonNewGame_Click(object sender, EventArgs e)
		{
			Game = new GlobalStates();
			UpdateGame();
		}

		private void buttonOpenGame_Click(object sender, EventArgs e)
		{
			OpenFileDialog op = new OpenFileDialog();
			op.Multiselect = false;
			op.ShowDialog();
			if (op.FileName.Length < 1)
				op.FileName = "DEFAULTSAVE";

			Game = Save.Load(op.FileName);
			UpdateGame();
		}

		private void buttonSave_Click(object sender, EventArgs e)
		{
			//called when game information is saved
			SaveFileDialog sf = new SaveFileDialog();
			sf.ShowDialog();
			if (sf.FileName.Length < 1)
				sf.FileName = "DEFAULTSAVE";

			Save.SaveGame(sf.FileName, Game);
		}

		
		/// <summary>
		/// re_updates all data from game into form1.
		/// 
		/// </summary>
		public void UpdateGame()
		{
			textBoxAuthorName.Text = Game.AuthorName;
			textBoxProjectName.Text = Game.ProjectName;
			textBoxStoryHeadline.Text = Game.StoryHeadline;

			//update thing list
			listBoxThings.Items.Clear();
			listBoxThingPersons.Items.Clear();
			domainUpDownThingTypesOfThings.Items.Clear();
			foreach (Thing t in Game.Things)
			{
				listBoxThings.Items.Add(t);
				domainUpDownThingTypesOfThings.Items.Add(t);
				if (t.Type == 1 || t.Type == 3 || t.Type == 4 || t.Type == 5 || t.Type == 6)//1 is type person
					listBoxThingPersons.Items.Add(t);
			}


			//update usercommand list
			listBoxUserCommands.Items.Clear();
			foreach (UserCommand u in Game.UserCommands)
			{
				listBoxUserCommands.Items.Add(u);

			}


			//update action list
			listBoxActions.Items.Clear();
			foreach (Action u in Game.Actions)
			{
				listBoxActions.Items.Add(u);

			}


			


			//update Room list
			listBoxRooms.Items.Clear();
			listBoxRoomNorth.Items.Clear();
			listBoxRoomEast.Items.Clear();
			listBoxRoomSouth.Items.Clear();
			listBoxRoomWest.Items.Clear();
			listBoxRoomAbove.Items.Clear();
			listBoxRoomBeneath.Items.Clear();
			foreach (Room r in Game.Rooms)
			{
				listBoxRooms.Items.Add(r);
				listBoxRoomNorth.Items.Add(r);
				listBoxRoomEast.Items.Add(r);
				listBoxRoomSouth.Items.Add(r);
				listBoxRoomWest.Items.Add(r);
				listBoxRoomAbove.Items.Add(r);
				listBoxRoomBeneath.Items.Add(r);
			}


			//update rooms
			if (selectedRoom != -1 && listBoxRooms.Items.Count > 0)
			{
				listBoxRooms.SelectedIndex = selectedRoom;

				if (listBoxRoomEast.Items.Count > 0)
					listBoxRoomEast.SelectedIndex = selectedRoomE;
				if (listBoxRoomNorth.Items.Count > 0)
					listBoxRoomNorth.SelectedIndex = selectedRoomN;
				if (listBoxRoomSouth.Items.Count > 0)
					listBoxRoomSouth.SelectedIndex = selectedRoomS;
				if (listBoxRoomWest.Items.Count > 0)
					listBoxRoomWest.SelectedIndex = selectedRoomW;
				if (listBoxRoomAbove.Items.Count > 0)
					listBoxRoomAbove.SelectedIndex = selectedRoomU;
				if (listBoxRoomBeneath.Items.Count > 0)
					listBoxRoomBeneath.SelectedIndex = selectedRoomD;
			}


			//update userCommand
			if (selectedUserCommand != -1 && listBoxUserCommands.Items.Count > 0)
			{
				listBoxUserCommands.SelectedIndex = selectedUserCommand;
			}

			//update Action
			if (selectedAction != -1 && listBoxActions.Items.Count > 0)
			{
				listBoxActions.SelectedIndex = selectedAction;
			}

			//update things
			if (selectedThing != -1 && listBoxThings.Items.Count > 0)
			{
				listBoxThings.SelectedIndex = selectedThing;

			}

			//update persons
			if (selectedPerson != -1 && listBoxThingPersons.Items.Count > 0)
			{
				listBoxThingPersons.SelectedIndex = selectedPerson;

			}

			//default selection made if atleast one item is available
			if (selectedThing == -1 && listBoxThings.Items.Count > 0)
				listBoxThings.SelectedIndex = 0;
			if (selectedPerson == -1 && listBoxThingPersons.Items.Count > 0)
				listBoxThingPersons.SelectedIndex = 0;
			if (selectedUserCommand == -1 && listBoxUserCommands.Items.Count > 0)
				listBoxUserCommands.SelectedIndex = 0;
			if (selectedRoom == -1 && listBoxRooms.Items.Count > 0)
				listBoxRooms.SelectedIndex = 0;
			if (selectedAction == -1 && listBoxActions.Items.Count > 0)
				listBoxActions.SelectedIndex = 0;
			

			//update extensions
			loadExtensionTab();

			updateADVBookChoices();
		}

		

		private void buttonCopyToClipBoard1_Click(object sender, EventArgs e)
		{

			if (richTextBoxGameCode.Text.Length > 0)
			{
				richTextBoxGameCode.SelectAll();
				richTextBoxGameCode.Copy();
			}
		}

		private void buttonGenerateGameCode_Click(object sender, EventArgs e)
		{
			string[] parameters = { };//parameters for compile and debuging
			richTextBoxDebugOutput.Text = GenerateCode.debug(parameters, Game);
			richTextBoxGameCode.Text = GenerateCode.Compile(parameters, Game);
		}

		#endregion


		#region Room


		private void textBoxRoomDescription_TextChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1)
			{

				Game.Rooms.ElementAt(selectedRoom).Description = textBoxRoomDescription.Text;
				UpdateGame();
			}
		}

		private void textBoxRoomPrintedName_TextChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1)
			{

				Game.Rooms.ElementAt(selectedRoom).PrintedName = textBoxRoomPrintedName.Text;
				UpdateGame();
			}
		}

		private void loadRoomData()
		{
			textBoxRoomPrintedName.Text = Game.Rooms.ElementAt(selectedRoom).PrintedName;
			checkBoxRoomIsDark.Checked = Game.Rooms.ElementAt(selectedRoom).RoomIsDark;
			textBoxRoomDescription.Text = Game.Rooms.ElementAt(selectedRoom).Description;

			if (Game.Rooms.ElementAt(selectedRoom).LinkedRooms[0] != null)//north
			{
				listBoxRoomNorth.SelectedIndex =
					listBoxRoomNorth.Items.IndexOf(Game.Rooms.ElementAt(selectedRoom).LinkedRooms[0]);
			}
			else
			{
				listBoxRoomNorth.SelectedIndex = -1;
				selectedRoomN = -1;
			}

			if (Game.Rooms.ElementAt(selectedRoom).LinkedRooms[1] != null)//east
			{
				listBoxRoomEast.SelectedIndex =
					listBoxRoomEast.Items.IndexOf(Game.Rooms.ElementAt(selectedRoom).LinkedRooms[1]);
			}
			else
			{
				listBoxRoomEast.SelectedIndex = -1;
				selectedRoomE = -1;
			}

			if (Game.Rooms.ElementAt(selectedRoom).LinkedRooms[2] != null)//south
			{
				listBoxRoomSouth.SelectedIndex =
					listBoxRoomSouth.Items.IndexOf(Game.Rooms.ElementAt(selectedRoom).LinkedRooms[2]);
			}
			else
			{
				listBoxRoomSouth.SelectedIndex = -1;
				selectedRoomS = -1;
			}

			if (Game.Rooms.ElementAt(selectedRoom).LinkedRooms[3] != null)//south
			{
				listBoxRoomWest.SelectedIndex =
					listBoxRoomWest.Items.IndexOf(Game.Rooms.ElementAt(selectedRoom).LinkedRooms[3]);
			}
			else
			{
				listBoxRoomWest.SelectedIndex = -1;
				selectedRoomW = -1;
			}

			if (Game.Rooms.ElementAt(selectedRoom).LinkedRooms[4] != null)//up
			{
				listBoxRoomAbove.SelectedIndex =
					listBoxRoomAbove.Items.IndexOf(Game.Rooms.ElementAt(selectedRoom).LinkedRooms[4]);
			}
			else
			{
				listBoxRoomAbove.SelectedIndex = -1;
				selectedRoomU = -1;
			}

			if (Game.Rooms.ElementAt(selectedRoom).LinkedRooms[5] != null)//Down
			{
				listBoxRoomBeneath.SelectedIndex =
					listBoxRoomBeneath.Items.IndexOf(Game.Rooms.ElementAt(selectedRoom).LinkedRooms[5]);
			}
			else//clear
			{
				listBoxRoomBeneath.SelectedIndex = -1;
				selectedRoomD = -1;
			}

		}

		private void listBoxRoomAbove_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			//clear list
			selectedRoomU = -1;
			listBoxRoomAbove.SelectedIndex = -1;
			Game.Rooms.ElementAt(selectedRoom).LinkedRooms[4] = null;
		}

		private void listBoxRoomAbove_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1 && listBoxRoomAbove.Items.Count > 0)
			{
				selectedRoomU = listBoxRoomAbove.SelectedIndex;
				Game.Rooms.ElementAt(selectedRoom).LinkedRooms[4] = (Room)listBoxRoomAbove.SelectedItem;
			}
		}

		private void listBoxRoomBeneath_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			//clear list
			selectedRoomD = -1;
			listBoxRoomBeneath.SelectedIndex = -1;
			Game.Rooms.ElementAt(selectedRoom).LinkedRooms[5] = null;
		}

		private void listBoxRoomBeneath_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1 && listBoxRoomBeneath.Items.Count > 0)
			{
				selectedRoomD = listBoxRoomBeneath.SelectedIndex;
				Game.Rooms.ElementAt(selectedRoom).LinkedRooms[5] = (Room)listBoxRoomBeneath.SelectedItem;
			}
		}

		private void listBoxRoomEast_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			//clear list
			selectedRoomE = -1;
			listBoxRoomEast.SelectedIndex = -1;
			Game.Rooms.ElementAt(selectedRoom).LinkedRooms[1] = null;
		}

		private void listBoxRoomEast_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1 && listBoxRoomEast.Items.Count > 0)
			{
				selectedRoomE = listBoxRoomEast.SelectedIndex;
				Game.Rooms.ElementAt(selectedRoom).LinkedRooms[1] = (Room)listBoxRoomEast.SelectedItem;
			}
		}

		private void listBoxRoomNorth_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			//clear list
			selectedRoomN = -1;
			listBoxRoomNorth.SelectedIndex = -1;
			Game.Rooms.ElementAt(selectedRoom).LinkedRooms[0] = null;
		}

		private void listBoxRoomNorth_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1 && listBoxRoomNorth.Items.Count > 0)
			{
				selectedRoomN = listBoxRoomNorth.SelectedIndex;
				Game.Rooms.ElementAt(selectedRoom).LinkedRooms[0] = (Room)listBoxRoomNorth.SelectedItem;
			}
		}

		private void listBoxRooms_SelectedIndexChanged(object sender, EventArgs e)
		{
			//usercommand list box index change
			selectedRoom = listBoxRooms.SelectedIndex;
			loadRoomData();
		}

		private void listBoxRoomSouth_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			//clear list
			selectedRoomS = -1;
			listBoxRoomSouth.SelectedIndex = -1;
			Game.Rooms.ElementAt(selectedRoom).LinkedRooms[2] = null;
		}

		private void listBoxRoomSouth_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1 && listBoxRoomSouth.Items.Count > 0)
			{
				selectedRoomS = listBoxRoomSouth.SelectedIndex;
				Game.Rooms.ElementAt(selectedRoom).LinkedRooms[2] = (Room)listBoxRoomSouth.SelectedItem;
			}
		}

		private void listBoxRoomWest_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			//clear list
			selectedRoomW = -1;
			listBoxRoomWest.SelectedIndex = -1;
			Game.Rooms.ElementAt(selectedRoom).LinkedRooms[3] = null;
		}

		private void listBoxRoomWest_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1 && listBoxRoomWest.Items.Count > 0)
			{
				selectedRoomW = listBoxRoomWest.SelectedIndex;
				Game.Rooms.ElementAt(selectedRoom).LinkedRooms[3] = (Room)listBoxRoomWest.SelectedItem;
			}
		}

		private void checkBoxRoomIsDark_CheckedChanged(object sender, EventArgs e)
		{
			if (selectedRoom != -1)
			{

				Game.Rooms.ElementAt(selectedRoom).RoomIsDark = checkBoxRoomIsDark.Checked;
				UpdateGame();
			}
		}

		private void buttonRoomDeleteSelectedRoom_Click(object sender, EventArgs e)
		{
			//Room delete pressed
			if (selectedRoom != -1)
			{
				Game.Rooms.RemoveAt(selectedRoom);
				selectedRoom = -1;//back to default
			}

			UpdateGame();
		}

		private void buttonRoomsNewRoom_Click(object sender, EventArgs e)
		{
			//creates new Room
			//string response = Microsoft.VisualBasic.Interaction.InputBox("Internal Name of New Room", "New Room", "New" + Game.Rooms.Count, 0, 0);

			string response = "New" + Game.Rooms.Count;

			if (InputBox("New Room", "Internal Name of New Room", ref response) != DialogResult.OK)
			{
				response = "New" + Game.Rooms.Count;
			}


			if (response.Length > 0)
			{
				Game.Rooms.Add(new Room()
				{
					InternalName = response
				});
			}

			UpdateGame();
		}

		#endregion


		#region Action

		private void textBoxActionName_TextChanged(object sender, EventArgs e)
		{
			if (selectedAction != -1)
			{

				Game.Actions.ElementAt(selectedAction).NameOfAction = textBoxActionName.Text;
				UpdateGame();
			}
		}

		private void textBoxActionTypeOfObject_TextChanged(object sender, EventArgs e)
		{
			if (selectedAction != -1)
			{

				Game.Actions.ElementAt(selectedAction).TypeOfObject = textBoxActionTypeOfObject.Text;
				UpdateGame();
			}
		}

		private void loadActionData()
		{//loads all Action data from selected index into form
			if (selectedAction != -1)
			{
				domainUpDownActionNumberOfObjects.SelectedIndex = Game.Actions.ElementAt(selectedAction).ChosenNumberOfObjects;
				domainUpDownActionOptionalLit.SelectedIndex = Game.Actions.ElementAt(selectedAction).ChosenOptionalLit;
				domainUpDownActionRequirenments.SelectedIndex = Game.Actions.ElementAt(selectedAction).ChosenRequirenment;
				textBoxActionName.Text = Game.Actions.ElementAt(selectedAction).NameOfAction;
				textBoxActionTypeOfObject.Text = Game.Actions.ElementAt(selectedAction).TypeOfObject;
			}
		}

		private void listBoxActions_SelectedIndexChanged(object sender, EventArgs e)
		{
			//usercommand list box index change
			selectedAction = listBoxActions.SelectedIndex;
			loadActionData();
		}

		private void domainUpDownActionNumberOfObjects_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedAction != -1)
			{

				Game.Actions.ElementAt(selectedAction).ChosenNumberOfObjects = domainUpDownActionNumberOfObjects.SelectedIndex;
				UpdateGame();
			}
		}

		private void domainUpDownActionOptionalLit_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedAction != -1)
			{

				Game.Actions.ElementAt(selectedAction).ChosenOptionalLit = domainUpDownActionOptionalLit.SelectedIndex;
				UpdateGame();
			}
		}

		private void domainUpDownActionRequirenments_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedAction != -1)
			{

				Game.Actions.ElementAt(selectedAction).ChosenRequirenment = domainUpDownActionRequirenments.SelectedIndex;
				UpdateGame();
			}
		}

		private void buttonActionsDeleteSelectedAction_Click(object sender, EventArgs e)
		{
			//user command delete pressed
			if (selectedAction != -1)
			{
				Game.Actions.RemoveAt(selectedAction);
				selectedAction = -1;//back to default
			}

			UpdateGame();
		}

		private void buttonActionsNewAction_Click(object sender, EventArgs e)
		{
			//user command new pressed
			int id = 0;
			if (Game.Actions.Count == 0)
				id = Game.Actions.Count;
			else
				id = Game.Actions.ElementAt(Game.Actions.Count - 1).ID + 1;

			Game.Actions.Add(new Action()
			{
				ID = id

			});

			UpdateGame();
		}

		#endregion


		#region Thing

		private void textBoxThingCustomType_TextChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).CustomType = textBoxThingCustomType.Text;
				Game.Things.ElementAt(selectedThing).ThingType = null;
				Game.Things.ElementAt(selectedThing).Type = -1;
				UpdateGame();
			}
		}

		private void textBoxThingIndefiniteArticle_TextChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).IndefiniteArticle = textBoxThingIndefiniteArticle.Text;
				UpdateGame();
			}
		}

		private void textBoxThingInventoryListing_TextChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).InventoryListing = textBoxThingInventoryListing.Text;
				UpdateGame();
			}
		}

		private void textBoxThingPluralName_TextChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).PluralName = textBoxThingPluralName.Text;
				UpdateGame();
			}
		}

		private void textBoxThingPrintedName_TextChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).PrintedName = textBoxThingPrintedName.Text;
				UpdateGame();
			}
		}
		
		private void loadThingData()
		{//loads all thing data from selected index into form 1
			if (selectedThing != -1)
			{
				textBoxThingPrintedName.Text = Game.Things.ElementAt(selectedThing).PrintedName;

				if (Game.Things.ElementAt(selectedThing).Type != -1)
					domainUpDownThingType.SelectedIndex = Game.Things.ElementAt(selectedThing).Type;

				if (Game.Things.ElementAt(selectedThing).ThingType != null)
					domainUpDownThingTypesOfThings.SelectedItem = Game.Things.ElementAt(selectedThing).ThingType;

				checkBoxThingKindOf.Checked = Game.Things.ElementAt(selectedThing).KindOf;
				textBoxThingPluralName.Text = Game.Things.ElementAt(selectedThing).PluralName;
				textBoxThingIndefiniteArticle.Text = Game.Things.ElementAt(selectedThing).IndefiniteArticle;
				textBoxThingInventoryListing.Text = Game.Things.ElementAt(selectedThing).InventoryListing;
				checkBoxThingPluralNamed.Checked = Game.Things.ElementAt(selectedThing).PluralNamed;
				checkBoxThingProperNamed.Checked = Game.Things.ElementAt(selectedThing).ProperNamed;
				checkBoxThingVaries.Checked = Game.Things.ElementAt(selectedThing).Varies;
				textBoxThingCustomType.Text = Game.Things.ElementAt(selectedThing).CustomType;
			}
		}

		private void listBoxThingPersons_SelectedIndexChanged(object sender, EventArgs e)
		{
			//update selection
			selectedPerson = listBoxThingPersons.SelectedIndex;
		}

		private void listBoxThings_SelectedIndexChanged(object sender, EventArgs e)
		{
			//update selection
			selectedThing = listBoxThings.SelectedIndex;
			loadThingData();
		}

		private void domainUpDownThingKindOf_SelectedItemChanged(object sender, EventArgs e)
		{//Thing types
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).ThingType = (Thing)domainUpDownThingTypesOfThings.SelectedItem;
				textBoxThingCustomType.Text = "";//clears custom type
				Game.Things.ElementAt(selectedThing).Type = -1;
				UpdateGame();
			}
		}

		private void domainUpDownThingType_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).Type = domainUpDownThingType.SelectedIndex;
				Game.Things.ElementAt(selectedThing).ThingType = null;
				textBoxThingCustomType.Text = "";//clears custom type
				UpdateGame();
			}
		}

		private void checkBoxThingKindOf_CheckedChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).KindOf = checkBoxThingKindOf.Checked;
				UpdateGame();
			}
		}

		private void checkBoxThingPluralNamed_CheckedChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).PluralNamed = checkBoxThingPluralNamed.Checked;
				UpdateGame();
			}
		}

		private void checkBoxThingProperNamed_CheckedChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).ProperNamed = checkBoxThingProperNamed.Checked;
				UpdateGame();
			}
		}

		private void checkBoxThingVaries_CheckedChanged(object sender, EventArgs e)
		{
			if (selectedThing != -1)
			{
				Game.Things.ElementAt(selectedThing).Varies = checkBoxThingVaries.Checked;
				UpdateGame();
			}
		}

		private void buttonThingDelete_Click(object sender, EventArgs e)
		{
			//delete selected thing

			if (selectedThing != -1)
			{
				Game.Things.RemoveAt(selectedThing);
				selectedThing = -1;//back to default
			}

			UpdateGame();
		}

		private void buttonNewThing_Click(object sender, EventArgs e)
		{
			//creates new thing
			// string response = Microsoft.VisualBasic.Interaction.InputBox("Internal Name of New Thing", "New Thing", "New" + Game.Things.Count, 0, 0);
			string response = "New" + Game.Things.Count;

			if (InputBox("New Thing", "Internal Name of New Thing", ref response) != DialogResult.OK)
			{
				response = "New" + Game.Things.Count;
			}

			if (response.Length > 0)
			{
				Game.Things.Add(new Thing()
				{
					InternalName = response
				});
			}

			UpdateGame();
		}

		#endregion


		#region UserCommand

		private void textBoxUserCommandLogicTestString_TextChanged(object sender, EventArgs e)
		{
			if (selectedUserCommand != -1)
			{

				Game.UserCommands.ElementAt(selectedUserCommand).LogicTestString = textBoxUserCommandLogicTestString.Text;
				UpdateGame();
			}
		}

		private void textBoxUserCommandReplacementString_TextChanged(object sender, EventArgs e)
		{
			if (selectedUserCommand != -1)
			{

				Game.UserCommands.ElementAt(selectedUserCommand).ReplacementString = textBoxUserCommandReplacementString.Text;
				UpdateGame();
			}
		}

		private void loadUserCommandData()
		{//loads all command data from selected index into form
			if (selectedUserCommand != -1)
			{
				domainUpDownUserCommandLogic.SelectedIndex = Game.UserCommands.ElementAt(selectedUserCommand).ChosenLogic;
				domainUpDownUserCommandAction.SelectedIndex = Game.UserCommands.ElementAt(selectedUserCommand).ChosenAction;
				domainUpDownUserCommandArguments.SelectedIndex = Game.UserCommands.ElementAt(selectedUserCommand).ChosenArgument;
				textBoxUserCommandLogicTestString.Text = Game.UserCommands.ElementAt(selectedUserCommand).LogicTestString;
				textBoxUserCommandReplacementString.Text = Game.UserCommands.ElementAt(selectedUserCommand).ReplacementString;

			}
		}

		private void listBoxUserCommands_SelectedIndexChanged(object sender, EventArgs e)
		{
			//usercommand list box index change
			selectedUserCommand = listBoxUserCommands.SelectedIndex;
			loadUserCommandData();
		}

		private void domainUpDownUserCommandAction_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedUserCommand != -1)
			{

				Game.UserCommands.ElementAt(selectedUserCommand).ChosenAction = domainUpDownUserCommandAction.SelectedIndex;
				UpdateGame();
			}
		}

		private void domainUpDownUserCommandArguments_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedUserCommand != -1)
			{

				Game.UserCommands.ElementAt(selectedUserCommand).ChosenArgument = domainUpDownUserCommandArguments.SelectedIndex;
				UpdateGame();
			}
		}

		private void domainUpDownUserCommandLogic_SelectedItemChanged(object sender, EventArgs e)
		{
			if (selectedUserCommand != -1)
			{

				Game.UserCommands.ElementAt(selectedUserCommand).ChosenLogic = domainUpDownUserCommandLogic.SelectedIndex;
				UpdateGame();
			}
		}

		private void buttonUserCommandDeleteSelectedCommand_Click(object sender, EventArgs e)
		{
			//user command delete pressed
			if (selectedUserCommand != -1)
			{
				Game.UserCommands.RemoveAt(selectedUserCommand);
				selectedUserCommand = -1;//back to default
			}

			UpdateGame();
		}

		private void buttonUserCommandNewCommand_Click(object sender, EventArgs e)
		{
			//user command new pressed
			int id = 0;
			if (Game.UserCommands.Count == 0)
				id = Game.UserCommands.Count;
			else
				id = Game.UserCommands.ElementAt(Game.UserCommands.Count - 1).ID + 1;

			Game.UserCommands.Add(new UserCommand()
			{
				ID = id

			});

			UpdateGame();
		}

		#endregion UserCommand


		#region Extensions

		#region ADVBook

		#region ExtensionTab

		//activates/deactivates Adventure Book Mode
		private void checkBoxAdventureBook_CheckedChanged(object sender, EventArgs e)
		{
			Game.Extensions.ADVENTUREBOOK = checkBoxAdventureBook.Checked;
		}

		//loads all data in extensions tab
		private void loadExtensionTab()
		{
			checkBoxAdventureBook.Checked = Game.Extensions.ADVENTUREBOOK;
		}

		#endregion ExtensionTab
		

		#region Page

		private void buttonAdventureBookNewPage_Click(object sender, EventArgs e)
		{
			string response = "New" + Game.Extensions.ListOfPages.Count;

			if (InputBox("New Page", "Internal Name of New Page", ref response) != DialogResult.OK)
			{
				response = "New" + Game.Extensions.ListOfPages.Count;
			}

			if (response.Length > 0)
			{
				Game.Extensions.ListOfPages.Add(new ADVBookPage()
				{
					InternalName = response
				});
			}

			//establishes a first default page
			if (Game.Extensions.ListOfPages.Count == 1) { Game.Extensions.ListOfPages.ElementAt(0).FirstPage = true; }

			updateADVBookPages();
		}


		private void buttonAdventureBookDeletePage_Click(object sender, EventArgs e)
		{
			//delete selected page

			if (selectedADVBookPage != -1)
			{
				Game.Extensions.ListOfPages.RemoveAt(selectedADVBookPage);
				selectedADVBookPage = -1;//back to default
			}

			updateADVBookPages();
		}


		private void listBoxAdventureBookPages_SelectedIndexChanged(object sender, EventArgs e)
		{
			//update selection
			selectedADVBookPage = listBoxAdventureBookPages.SelectedIndex;
			selectedADVBookChoice = -1;//resets to default for choice list
			loadAdventureBookPagesData();
			updateADVBookChoices();
		}


		//text is changed, no update needed
		private void richTextBoxAdventureBookDefaultPageContent_TextChanged(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DefaultPageContent =
					richTextBoxAdventureBookDefaultPageContent.Text;
			}
		}


		//looses focus
		private void richTextBoxAdventureBookDefaultPageContent_Leave(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DefaultPageContent =
					richTextBoxAdventureBookDefaultPageContent.Text;
				updateADVBookPages();
			}
		}


		//records last position of caret
		private void richTextBoxAdventureBookDefaultPageContent_MouseClick(object sender, MouseEventArgs e)
		{
			caretPos = richTextBoxAdventureBookDefaultPageContent.SelectionStart;
		}


		//inserts <cond> marker at cursor in text, then counts how many you have
		private void buttonInsertCondBranchMarker_Click(object sender, EventArgs e)
		{
			if (caretPos > richTextBoxAdventureBookDefaultPageContent.TextLength)
				caretPos = 0;

			richTextBoxAdventureBookDefaultPageContent.SelectionStart = caretPos;
			richTextBoxAdventureBookDefaultPageContent.SelectedText = "<cond>";

			if (selectedADVBookPage != -1)
			{
				//count the number of <cond> in rich text box with regex
				MatchCollection match =
					Regex.Matches(richTextBoxAdventureBookDefaultPageContent.Text, @"<cond>", RegexOptions.IgnoreCase);
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).NumCond = match.Count;
			}
		}


		private void loadAdventureBookPagesData()
		{
			//loads data for specific page into form

			if (selectedADVBookPage != -1)
			{
				//text------------------------------------------------------------------
				richTextBoxAdventureBookDefaultPageContent.Text = 
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DefaultPageContent;


				//combo box-load---------------------------------------------------------
				comboBoxADVBookPagesJumpToPage.Items.Clear();
				comboBoxADVBookPagesJumpToPage.Items.Add("");
				foreach (ADVBookPage p in Game.Extensions.ListOfPages)
				{
					comboBoxADVBookPagesJumpToPage.Items.Add(p.InternalName);
				}

				//combo box-select--------------------------------------------------------
				String FP = Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).FollowingPage;
				if (FP != "" &&
					comboBoxADVBookPagesJumpToPage.Items.Contains(FP))
				{
					comboBoxADVBookPagesJumpToPage.SelectedIndex =
						comboBoxADVBookPagesJumpToPage.Items.IndexOf(FP);
				}
				else
				{
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).FollowingPage = "";
					comboBoxADVBookPagesJumpToPage.SelectedIndex = 0;
				}


				//settings------------------------------------------------------------------
				if (Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd)
					checkedListBoxADVBookPagesSettings.SetItemChecked(0, true);
				else
					checkedListBoxADVBookPagesSettings.SetItemChecked(0, false);

				if (Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove)
				{
					checkedListBoxADVBookPagesSettings.SetItemChecked(1, true);
					comboBoxADVBookPagesJumpToPage.Enabled = true;
				}
				else
				{
					checkedListBoxADVBookPagesSettings.SetItemChecked(1, false);
					comboBoxADVBookPagesJumpToPage.Enabled = false;
				}

				if (Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).FirstPage)
					checkedListBoxADVBookPagesSettings.SetItemChecked(2, true);
				else
					checkedListBoxADVBookPagesSettings.SetItemChecked(2, false);
			}
		}

		private void checkedListBoxADVBookPagesSettings_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1)
			{
				if (checkedListBoxADVBookPagesSettings.GetItemChecked(0) //dead end
					&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove != true)//flags that enable
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd = true;
				else
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd = false;


				if (checkedListBoxADVBookPagesSettings.GetItemChecked(1)//linear move
					&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd != true)//flags that cancell
				{
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove = true;
					comboBoxADVBookPagesJumpToPage.Enabled = true;
				}
				else
				{
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove = false;
					comboBoxADVBookPagesJumpToPage.Enabled = false;
				}

				if (checkedListBoxADVBookPagesSettings.GetItemChecked(2))//first page
				{
					foreach (ADVBookPage p in Game.Extensions.ListOfPages)//restore all back to default
					{
						p.FirstPage = false;
					}

					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).FirstPage = true;//set new page as first
				}

				loadAdventureBookPagesData();
			}
		}

		private void comboBoxADVBookPagesJumpToPage_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1 && comboBoxADVBookPagesJumpToPage.SelectedItem != null)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).FollowingPage =
					(String)comboBoxADVBookPagesJumpToPage.SelectedItem;
			}
		}

		private void updateADVBookPages()
		{
			//update adventurebookpage list
			listBoxAdventureBookPages.Items.Clear();
			foreach (ADVBookPage u in Game.Extensions.ListOfPages)
			{
				listBoxAdventureBookPages.Items.Add(u);

			}

			//update ADVBook Page
			if (selectedADVBookPage != -1 && listBoxAdventureBookPages.Items.Count > 0)
			{
				listBoxAdventureBookPages.SelectedIndex = selectedADVBookPage;
			}


			if (selectedADVBookPage == -1 && listBoxAdventureBookPages.Items.Count > 0)
				listBoxAdventureBookPages.SelectedIndex = 0;

			//update extensions
			loadExtensionTab();
			loadAdventureBookPagesData();
			updateADVBookChoices();
		}

		#endregion Page


		#region Choices

		private void buttonAdventureBookNewChoice_Click(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1 
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd == false 
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove == false)//there must be a page selected first
			{
				string response = "New" + Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.Count;

				if (InputBox("New Choice", "Internal Name of New Choice", ref response) != DialogResult.OK)
				{
					response = "New" + Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.Count;
				}

				if (response.Length > 0)
				{
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.Add(new ADVBookChoice()
					{
						InternalName = response
					});
				}

				updateADVBookChoices();
			}
		}


		private void buttonAdventureBookDeleteChoice_Click(object sender, EventArgs e)
		{
			//delete selected choice

			if (selectedADVBookPage != -1 && selectedADVBookChoice != -1
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd == false
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove == false)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.RemoveAt(selectedADVBookChoice);
				selectedADVBookChoice = -1;//back to default
			}

			updateADVBookChoices();
		}


		private void listBoxAdventureBookChoices_SelectedIndexChanged(object sender, EventArgs e)
		{
			//update selection
			selectedADVBookChoice = listBoxAdventureBookChoices.SelectedIndex;
			loadAdventureBookChoiceData();
		}


		private void loadAdventureBookChoiceData()
		{
			//clear combo box, will load new pages if they exist
			comboBoxADVBookChoicesTriggers.Items.Clear();

			//loads data for specific choice data into form
			if (selectedADVBookPage != -1 
				&& selectedADVBookChoice != -1 
				&& listBoxAdventureBookChoices.Items.Count > 0
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd == false
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove == false)
			{

				//combo box-load---------------------------------------------------------
				comboBoxADVBookChoicesTriggers.Items.Add("");
				foreach (ADVBookPage p in Game.Extensions.ListOfPages)
				{
					comboBoxADVBookChoicesTriggers.Items.Add(p.InternalName);
				}

				//combo box-select--------------------------------------------------------
				String FP = //FP is the page internal-name trigered by this choice
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).Triggers;
				
				if (FP != "" 
					&& comboBoxADVBookChoicesTriggers.Items.Contains(FP))
				{
					comboBoxADVBookChoicesTriggers.SelectedIndex =
						comboBoxADVBookChoicesTriggers.Items.IndexOf(FP);
				}
				else
				{
					//this is if FP is not null but the value is not a valid page.
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).Triggers = "";
					comboBoxADVBookChoicesTriggers.SelectedIndex = 0;
				}

				//update text boxes--------------------------------------------------------
				textBoxADVBChoicesName.Text = 
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).InternalName;
				textBoxADVBChoicesText.Text = 
					Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).Text;
			}
			else
			{
				textBoxADVBChoicesName.Text = "";
				textBoxADVBChoicesText.Text = "";
			}
		}


		//updates all choice related data, called when page index is changed.
		private void updateADVBookChoices()
		{
			listBoxAdventureBookChoices.Items.Clear();

			//when the first choice is added there will need to be an ititiation to 0;
			if (selectedADVBookChoice == -1
				&& selectedADVBookPage != -1
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.Count > 0)
				selectedADVBookChoice = 0;

			//only update if there is something to update
			if (selectedADVBookChoice != -1
				&& selectedADVBookPage != -1
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.Count > 0
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd == false
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove == false)
			{
				//update adventurebookchoice list
				if (selectedADVBookPage != -1)
					foreach (ADVBookChoice u in Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices)
					{
						listBoxAdventureBookChoices.Items.Add(u);
					}

				//update ADVBook Choice
				if (selectedADVBookChoice != -1 
					&& listBoxAdventureBookChoices.Items.Count > 0 
					&& selectedADVBookPage != -1 
					&& listBoxAdventureBookPages.Items.Count > 0)
				{
					listBoxAdventureBookChoices.SelectedIndex = selectedADVBookChoice;
				}

				//default selection made if atleast one item is available
				if (selectedADVBookChoice == -1 && listBoxAdventureBookChoices.Items.Count > 0)
					listBoxAdventureBookChoices.SelectedIndex = 0;
					
			}

			//last action is to update form items.
			loadAdventureBookChoiceData();//will update forms to null data
		}


		private void textBoxADVBChoicesName_TextChanged(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1 
				&& selectedADVBookChoice != -1
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd == false
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove == false)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).InternalName =
					textBoxADVBChoicesName.Text;
				updateADVBookChoices();
			}
		}


		private void textBoxADVBChoicesText_TextChanged(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1 
				&& selectedADVBookChoice != -1
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).DeadEnd == false
				&& Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).LinearMove == false)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).Text =
					textBoxADVBChoicesText.Text;
			}
		}


		private void checkedListBoxADVBookChoicesSettings_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (checkedListBoxADVBookChoicesSettings.GetItemChecked(0))//flags that enable
				checkedListBoxADVBookChoicesFlagsEnable.Enabled = true;
			else
				checkedListBoxADVBookChoicesFlagsEnable.Enabled = false;

			if (checkedListBoxADVBookChoicesSettings.GetItemChecked(1))//flags that cancell
				checkedListBoxADVBookChoicesFlagsCancell.Enabled = true;
			else
				checkedListBoxADVBookChoicesFlagsCancell.Enabled = false;
		}


		private void comboBoxADVBookChoicesTriggers_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (selectedADVBookPage != -1 
				&& comboBoxADVBookChoicesTriggers.SelectedItem != null 
				&& selectedADVBookChoice != -1)
			{
				Game.Extensions.ListOfPages.ElementAt(selectedADVBookPage).ListOfChoices.ElementAt(selectedADVBookChoice).Triggers =
					(String)comboBoxADVBookChoicesTriggers.SelectedItem;
			}
		}

		#endregion Choices


		#region Flags

		private void listBoxAdventureBookFlags_SelectedIndexChanged(object sender, EventArgs e)
		{
			//update selection
			selectedADVBookFlag = listBoxAdventureBookFlags.SelectedIndex;
			loadAdventureBookFlagsData();
		}

		private void buttonAdventureBookNewFlag_Click(object sender, EventArgs e)
		{
			string response = "New" + Game.Extensions.ListOfFlags.Count;

			if (InputBox("New Flag", "Internal Name of New Flag", ref response) != DialogResult.OK)
			{
				response = "New" + Game.Extensions.ListOfFlags.Count;
			}

			if (response.Length > 0)
			{
				Game.Extensions.ListOfFlags.Add(new ADVBookFlag()
				{
					InternalName = response
				});
			}

			updateADVBookFlags();
		}

		private void buttonAdventureBookDeleteFlag_Click(object sender, EventArgs e)
		{
			if (selectedADVBookFlag != -1)
			{
				Game.Extensions.ListOfFlags.RemoveAt(selectedADVBookFlag);
				selectedADVBookFlag = -1;//back to default
			}

			updateADVBookFlags();
		}

		private void textBoxAdventureBookFlagsInternalName_TextChanged(object sender, EventArgs e)
		{
			if (selectedADVBookFlag != -1)
			{
				Game.Extensions.ListOfFlags.ElementAt(selectedADVBookFlag).InternalName =
					textBoxAdventureBookFlagsInternalName.Text;
				updateADVBookFlags();
			}

		}

		private void checkBoxAdventureBookFlagsIsOn_CheckedChanged(object sender, EventArgs e)
		{
			if (selectedADVBookFlag != -1)
			{
				Game.Extensions.ListOfFlags.ElementAt(selectedADVBookFlag).On = checkBoxAdventureBookFlagsIsOn.Checked;
			}
		}

		private void loadAdventureBookFlagsData()
		{
			if (selectedADVBookFlag != -1)
			{
				//text------------------------------------------------------------------
				textBoxAdventureBookFlagsInternalName.Text =
					Game.Extensions.ListOfFlags.ElementAt(selectedADVBookFlag).InternalName;

				//check box-------------------------------------------------------------
				checkBoxAdventureBookFlagsIsOn.Checked =
					Game.Extensions.ListOfFlags.ElementAt(selectedADVBookFlag).On;
			}
		}

		private void updateADVBookFlags()
		{
			//update adventurebookpage list
			listBoxAdventureBookFlags.Items.Clear();
			foreach (ADVBookFlag u in Game.Extensions.ListOfFlags)
			{
				listBoxAdventureBookFlags.Items.Add(u);

			}

			//update ADVBook Page
			if (selectedADVBookFlag != -1 && listBoxAdventureBookFlags.Items.Count > 0)
			{
				listBoxAdventureBookFlags.SelectedIndex = selectedADVBookFlag;
			}


			if (selectedADVBookFlag == -1 && listBoxAdventureBookFlags.Items.Count > 0)
				listBoxAdventureBookFlags.SelectedIndex = 0;

			loadAdventureBookFlagsData();
		}

		#endregion Flags

		#endregion ADVBook

		#endregion Extensions

		#endregion Methods


		#region inputdialog

		//the following was taken from http://www.csharp-examples.net/inputbox/, thank you csharp examples!
		public static DialogResult InputBox(string title, string promptText, ref string value)
		{
			Form form = new Form();
			Label label = new Label();
			TextBox textBox = new TextBox();
			Button buttonOk = new Button();
			Button buttonCancel = new Button();

			form.Text = title;
			label.Text = promptText;
			textBox.Text = value;

			buttonOk.Text = "OK";
			buttonCancel.Text = "Cancel";
			buttonOk.DialogResult = DialogResult.OK;
			buttonCancel.DialogResult = DialogResult.Cancel;

			label.SetBounds(9, 20, 372, 13);
			textBox.SetBounds(12, 36, 372, 20);
			buttonOk.SetBounds(228, 72, 75, 23);
			buttonCancel.SetBounds(309, 72, 75, 23);

			label.AutoSize = true;
			textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
			buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
			buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

			form.ClientSize = new Size(396, 107);
			form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel });
			form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
			form.FormBorderStyle = FormBorderStyle.FixedDialog;
			form.StartPosition = FormStartPosition.CenterScreen;
			form.MinimizeBox = false;
			form.MaximizeBox = false;
			form.AcceptButton = buttonOk;
			form.CancelButton = buttonCancel;

			DialogResult dialogResult = form.ShowDialog();
			value = textBox.Text;
			return dialogResult;
		}

		#endregion


	}





}
